<template>
  <div>
    <van-search v-model="value" placeholder="商品搜索,共239款好物" />
    <!-- <li v-for="item in list" :key="item.id">{{item.name}}</li> -->
    <!-- 侧边导航  左边categoryList 右边currentOne-->
    <div class="content">
    <van-sidebar v-model="activeKey">
      <van-sidebar-item @click="getInfo(item)"  v-for="item in categoryList" :key="item.id" :title="item.name" />
    </van-sidebar>
    <div class="right">
      <!-- 图 -->
      <img class="banner" :src="list.banner_url" alt />
    <!-- 标题 -->
    <div class="stitle">
      <span>-</span>
      <span>{{list.name}}分类</span>
      <span>-</span>
    <!-- 陈列商品 -->
    <ul>
      <router-link :to="`category/categorylist?id=${item.id}`" tag="li" v-for="item in list.subList" :key="item.id">
        <img :src="item.wap_banner_url" alt />
        <p>{{item.name}}</p>
      </router-link>
    </ul>
    </div>
    </div>
  </div>
  </div>
</template> 

<script>
// [1]
// import {clearhistoryAction} from "@/api/search"
import { indexaction } from "@/api/category";
import { currentaction } from "@/api/category";
export default {
  data() {
    return {
      // [3]
      value: "",
      activeKey: 0,
      list: [],
      categoryList: [],
    //   currentOne: []=categoryList=list渲染用list就行,
    };
  },
  computed: {},
  // [1]
  created() {
    currentaction({
      id: 1005000,
    }).then((res) => {
      // [2]
    //   console.log(res);
      this.list = res.data.currentOne;
    });
  // 列表数据
    indexaction({}).then((res) => {
    //   console.log(res);
      this.categoryList = res.categoryList;
    });
  },

  mounted() {},

  methods: {
    // clear() {
    //   clearhistoryAction({
    //     openId: localStorage.getItem("openId"),
    //     goodId: 1070000,
    //   }).then((res) => {
    //     console.log(res);
    //   });
    // },
    // 点击获取相应数据
    getInfo(item) {
      currentaction({
        id: item.id,
      }).then((res) => {
        this.list = res.data.currentOne;
        console.log(this.list);
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.content{
    display: flex;
    justify-content: space-between;
    // padding-bottom: 50px;
    // padding-top: 44px;
    
    .right{
        flex-wrap: wrap;
        width: 294px;
        .banner{
            margin-top: 10px;
            width: 263px;
            height: 111px;
        }
        .stitle{
            margin-top: 20px;
            margin-bottom: 20px;
            span{
            font-size: 16px;
            letter-spacing: 2px;
            }
        }
        ul{ 
            margin: 0 auto;
            justify-content: space-between;
            display: flex;
            flex-wrap: wrap;
            width: 263px;
            li{ 
                width: 30%;
                margin-bottom: 12px;
                img{
                    width: 72px;
                    height: 72px;
                }
                p{
                    font-size: 12px;
                    // width: 30%;
                    text-align: center;
                    writing-mode:horizontal-tb;
                }
            }
        }

    }
}
</style>